﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Classes;
using FlightSystemDBLayer;


namespace FlightSystemControlLayer
{
    class SearcherCtr
    {
        IList<City> listOfCities;
        IList<Flight> listOfFlights;
        ICity dbCity;
        Searcher searcher;
        IFlight dbFlight;

        //Delete if still not used after finishing
        //City cityFrom;
        //City cityTo;
        //int seatsNo;
        //DateTime departureTime;
        //DateTime arrivalTime;
       

        public SearcherCtr()
        {
            dbCity = new DBCity();
            listOfCities = dbCity.GetDBCities();

            dbFlight = new DBFlight(listOfCities); // initiated flight db class with preset list of cities
            

            searcher = new Searcher(); 

        }
        public IList<City> getCityList() { //city list retrieved from database

            return listOfCities;
        }
        public ListOfConnections MakeASearch(City cityFrom, City cityTo, int noOfSeats, DateTime dateTime) 
        {
            listOfFlights = dbFlight.GetSpecifiedFlights(noOfSeats, dateTime);
            
            searcher.MakeAGraph(listOfCities, listOfFlights);
           

            IGraphImpl list = searcher.ReturnGraph();
            ListOfConnections conList = list.SearchForConnections(cityFrom, cityTo);

            searcher.fillTheConnections(cityFrom, cityTo, conList);
            Console.WriteLine(conList.GetConnectionList()[0].FlightList()[0].DepartureTime);
            
            
             Console.ReadLine();
             return conList;
        }
    }
}
